package com.sky.controller.admin;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import com.sky.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * packageName com.sky.controller.admin
 *
 * @author fenglai
 * @version JDK 11
 * @className OrdersController
 * @date 2023/12/4
 * @description TODO
 */
@RestController
@Api("用户订单模块")
@RequestMapping("/admin/order")
@Slf4j
public class OrdersController {

    @Autowired
    private OrderService orderService;

    /**
     * @param ordersPageQueryDTO: return Result<PageResult>
     *                            {@link Result<PageResult>}
     * @author fenglai
     * @date 2023/12/4 19:38
     * @description 订单搜索功能
     */

    @ApiOperation("订单搜索的功能")
    @GetMapping("/conditionSearch")
    public Result<PageResult> pageQueryOrders(OrdersPageQueryDTO ordersPageQueryDTO) {

        log.info("正在执行订单搜索的功能.........搜索信息为:{}", ordersPageQueryDTO);

        PageResult p = orderService.pageQueryOrders(ordersPageQueryDTO);

        return Result.success(p);

    }


    /**
     * @param id: return Result<OrderVO>
     *            {@link Result<OrderVO>}
     * @author fenglai
     * @date 2023/12/4 19:38
     * @description 根据id查询订单详情的功能
     */


    @ApiOperation("根据id查看订单详情的功能")
    @GetMapping("/details/{id}")
    public Result<OrderVO> selectOrderDetails(@PathVariable Long id) {

        log.info("正在执行根据id查看订单详情的功能..........id为:{}", id);

        OrderVO orderVO = orderService.selectOrderDetail(id);

        return Result.success(orderVO);
    }


    /**
     * @param : return Result<OrderStatisticsVO>
     *          {@link Result<OrderStatisticsVO>}
     * @author fenglai
     * @date 2023/12/4 19:50
     * @description 统计各个状态的订单数量功能
     */

    @ApiOperation("统计各个状态的订单数量的功能")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> countOrderStatusNumber() {

        log.info("正在执行根据各个状态的订单数量统计..........");

        OrderStatisticsVO orderStatisticsVO = orderService.countOrderStatusNumber();

        return Result.success(orderStatisticsVO);
    }


    /**
     * @param ordersCancelDTO: return Result
     *                         {@link Result}
     * @author fenglai
     * @date 2023/12/4 20:21
     * @description 取消订单的功能
     */
    @ApiOperation("取消订单的功能")
    @PutMapping("/cancel")
    public Result cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO) {

        log.info("正在执行取消订单的功能.....取消的信息为:{}", ordersCancelDTO);

        orderService.updateOrder(ordersCancelDTO);

        return Result.success();

    }


    /**
     * @param id: return Result
     *            {@link Result}
     * @author fenglai
     * @date 2023/12/4 20:20
     * @description 派送订单的功能
     */
    @ApiOperation("派送订单的功能")
    @PutMapping("/delivery/{id}")
    public Result deliveryOrder(@PathVariable Long id) {

        log.info("正在执行派送订单的功能................订单id为:{}", id);

        orderService.deliveryOrder(id);

        return Result.success();
    }


    /**
     * @param confirmDTO: return Result
     *                    {@link Result}
     * @author fenglai
     * @date 2023/12/4 20:35
     * @description 接单功能
     */
    @ApiOperation("接单功能")
    @PutMapping("/confirm")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO confirmDTO) {

        log.info("正在执行接单的功能.............接的单号Id为:{}", confirmDTO);

        orderService.comfirmOrder(confirmDTO);

        return Result.success();
    }

    /**
     * @param ordersRejectionDTO: return Result
     *                            {@link Result}
     * @author fenglai
     * @date 2023/12/4 20:55
     * @description 拒单的功能
     */

    @ApiOperation("拒单功能")
    @PutMapping("/rejection")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {

        log.info("正在执行拒单的功能........拒单的信息为:{}", ordersRejectionDTO);

        orderService.rejection(ordersRejectionDTO);

        return Result.success();
    }


    /**
     * @param id: return Result
     *            {@link Result}
     * @author fenglai
     * @date 2023/12/4 20:55
     * @description 完成订单的功能
     */
    @ApiOperation("完成订单的功能")
    @PutMapping("/complete/{id}")
    public Result completeOrder(@PathVariable Long id) {

        log.info("正在执行完成订单的功能..................订单id为:{}", id);

        orderService.completeOrder(id);

        return Result.success();
    }


}